﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace APPFrameworkStudy.Repository
{
    public interface IDataMapper<T>  where T : class,new()
    {
        #region 持久化数据
        bool Create(T item);
        bool Update(T item);
        bool Delete(T item);
        #endregion

        #region 获取所有数据
        IQueryable<T> GetQueryable();
        IList<T> GetAll();
        IList<T> GetAll(IQueryable<T> query);
        #endregion

        #region 获取分页数据
        //分页
        IList<T> GetPage(int pageIndex, int pageSize, out int total);
        IList<T> GetPage(IQueryable<T> query,int pageIndex, int pageSize, out int total);
        //根据条件获取分页数据
        IList<T> GetPageByCriteria(int pageIndex, int pageSize, out int total, Expression<Func<T, bool>> where);
        IList<T> GetPageByCriteria(IQueryable<T> query, int pageIndex, int pageSize, out int total, Expression<Func<T, bool>> where);
        #endregion

        #region 获取数量

        int GetCount();
        int GetCountByCriteria(Expression<Func<T, bool>> where);
        #endregion

        #region 根据主键获取对象

        //获取单个对象
        T GetByKey(object key);
        #endregion

        #region 根据条件获取数据

        IList<T> GetByCriteria(Expression<Func<T, bool>> where);
        IList<T> GetByCriteria(IQueryable<T> query, Expression<Func<T, bool>> where);
        #endregion
    }
}
